package com.itheima.app.controller;

import com.itheima.app.manager.VideoManager;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;

    /**
     * 查询小视频列表
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/smallVideos")
    public PageBeanVo findVideo(@RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize) {
        return videoManager.findVideo(pageNumber, pageSize);
    }

    /**
     * 发布小视频
     */
    @PostMapping("/smallVideos")
    public Map saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videoManager.saveVideo(videoThumbnail, videoFile);
        return null;
    }

    /**
     * 关注小视频用户
     */
    @PostMapping("/smallVideos/{uid}/userFocus")
    public Map saveUserFocus(@PathVariable("uid") Long videoUserId) {
        videoManager.saveUserFocus(videoUserId);
        return null;
    }

    /**
     * 取消关注小视频用户
     */
    @PostMapping("/smallVideos/{uid}/userUnFocus")
    public Map deleteUserFocus(@PathVariable("uid") Long videoUserId) {
        videoManager.deleteUserFocus(videoUserId);
        return null;
    }


    /**
     * 视频点赞
     * @param videoId
     * @return
     */
    @PostMapping("/smallVideos/{id}/like")
    public Map saveVideoLike(@PathVariable("id") String videoId) {
        videoManager.saveVideoLike(videoId);
        return null;
    }

    /**
     * 视频取消点赞
     * @param videoId
     * @return
     */
    @PostMapping("/smallVideos/{id}/dislike")
    public Map deleteVideoLike(@PathVariable("id") String videoId) {
        videoManager.deleteVideoLike(videoId);
        return null;
    }



    /**
     * 视频评论列表
     */
    @GetMapping("/smallVideos/{id}/comments")
    public PageBeanVo findVideoComment(@RequestParam(defaultValue = "1",name = "page")Integer pageNum,
            @RequestParam(defaultValue = "10",name = "pagesize")Integer pageSize,@PathVariable("id")String videoId) {
        return  videoManager.findVideoComment(pageNum,pageSize,videoId);
    }

    /**
     * 视频评论发布
     */
    @PostMapping("/smallVideos/{id}/comments")
    public Map saveVideoComment(@RequestBody Map<String,String> map) {
        String videoId = map.get("id");
        String content = map.get("comment");

        videoManager.saveVideoComment(videoId,content);
        return null;
    }

    /**
     * 视频评论点赞
     */
    @PostMapping("/smallVideos/comments/{id}/like")
    public Map videoCommentLike(@PathVariable("id") String contentId){
        videoManager.videoCommentLike(contentId);
        return null;
    }
    /**
     * 取消视频评论点赞
     */
    @PostMapping("/smallVideos/comments/{id}/dislike")
    public Map deleteVideoCommentLike(@PathVariable("id") String contentId) {
        videoManager.deleteVideoCommentLike(contentId);
        return null;
    }
}
